package com.simen.hellobytes.encrypt;

import java.io.FileInputStream;
import java.io.IOException;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;

/**
 * 证书工具类
 * (私钥签名,公钥验签)
 *
 * @author Created by Simen.
 * @date 创建日期 2018/9/25 11:01
 * @modify 修改者 Simen
 */
public class CertUtil {

    public static Certificate getCertificate(String certificateFilePath) throws CertificateException, IOException {
        //实例化证书工厂
        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
        //取得证书文件流
        FileInputStream in = new FileInputStream(certificateFilePath);
        //生成证书
        Certificate certificate = certificateFactory.generateCertificate(in);

        in.close();

        return certificate;
    }

    public static PublicKey getPublicKey(Certificate certificate) {
        return certificate.getPublicKey();
    }

}
